package cc.telecomdigital.tdstock.activity.groups;

import android.os.Bundle;
import android.widget.TabHost;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.Framework.ActivityGroupHost_Framework;
import cc.telecomdigital.tdstock.Framework.ActivityGroup_Framework;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.groups.stock.BMPCurrentStockInfoActivity;
import cc.telecomdigital.tdstock.activity.groups.stock.CurrentStockInfoActivity;

/**
 * Groups the archive activities, so they can stay within a tab of TabActivity
 * @author haibo
 *
 */
public class StockGroup extends  ActivityGroupHost_Framework
{

	public static StockGroup	group;
	public static TabHost	tabHost	= null;
	private static ActivityGroupController groupController = null;
	// private ArrayList<View> history;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//this.history = new ArrayList<View>();
		group = this;
		//set the default activity when enter the group
		/*View view = getLocalActivityManager().startActivity(
				CurrentStockInfoActivity.class.getSimpleName(),
				new Intent(this, CurrentStockInfoActivity.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION))
				.getDecorView();
		setContentView(view);*/

	}

	public static void forceToGoToRelatingTab()
	{
		if (tabHost != null)
		{
			tabHost.setCurrentTab(0); //force to go to tab 0
		}
	}

	@Override
	public void onBackPressed()
	{
		super.onBackPressed();
		getCurrentActivity().onBackPressed(); //do  back pressed action in BaseActivity.  need to  go back to the history page directly?
	}
	
	
	@Override
	public ActivityGroupController CreateActivityGroupHostController() {
//		if (groupController != null)
//			groupController.DestoryController();
				
		if (groupController == null)
			groupController = new ActivityGroupController(this);
		else
			groupController.UpdateGroupHost(this);
		return groupController;
	}

	@Override
	public Class<? extends ActivityGroup_Framework> GetPrimaryActivity() 
	{
		// BMP Mode  by ouyangzhihui 2011-10-13
		if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
			return BMPCurrentStockInfoActivity.class;
		else
			return CurrentStockInfoActivity.class;
	}
	
	
	/** For External Call **/
	public static ActivityGroupController GetActivityGroupHostControl()
	{
		return groupController;
	}
	

}